from pyPdf import PdfFileReader
import os


def match_pdf(filename, expression):
    ''' Checks whether the given pdf file contains the given expression, returns True or False respectively '''

    try :
        input = PdfFileReader(file(os.path.abspath(filename), "rb"))
    except PdfReadError:
        print 'Pdf Reading Error encountered (wrong file passed?)'
        return False

    for page in input.pages:
        if expression.lower() in page.extractText().lower():
            return True
    
    return False
